Ext.define('MyApp.controller.user.UserController', {
	extend : 'MyApp.controller.share.BaseGridController',
	views : ['user.UserView','user.UserForm'],
	stores : ['UserStore'],
	models : ['UserEntity'],
	requires : ['Ext.ux.ProgressBarPager'],
	refs : [
			{ ref: 'userview', selector: 'userview' }
	],
	init : function() {
		this.control({
			//为选中时按钮不可用
			'userview': {
				select: function(){
					this.onGridSelect(this.getUserview());
				},
				deselect: function(){
					this.onGridDSelect(this.getUserview());
				}
			},
			'userview button#add' : {
	        	click:function(btn){
					this.onAddButtonClick('userForm');
				}
	        },
	        'userview button#edit' : {
	        	click:function(btn){
	        		this.onEditButtonClick(btn,'userview','userForm');
	        	}
	        },
	        'userForm textfield[name=loginID]':{
	        	blur:function( tf, The, eOpts ){
	        	}
	        },
	        'userview button#delete' : {
	        	click:function(btn){
	        		this.onDeleteButtonClick(btn,'userview');
	        	}
	        },
	        'userForm button#save':{
	        	click:function(btn){
	        		var me = this;
	        		me.onSaveButtonClick(btn,me.getUserStoreStore(),me.getUserEntityModel());
	        	}
	        },
	        'userForm button#cancel':{
	        	click:'onCancelButtonClick'
	        },
	        'userview button#resetpass' : {
	        	click:'onResetpassButtonClick'
	        }
		});
	},
	onResetpassButtonClick:function(btn){
		Ext.MessageBox.confirm('提示', '确定要重置密码吗?', function showResult(btnResult){
					   		if(btnResult=='yes'){
					   			var record = btn.up('userview').getSelectionModel().getLastSelected();
					   			record.set('password','6978915ee7dbc5aff1bc34b59e8c0fc5');
					   			Ext.Ajax.request({
								    url: 'user/resetPassword',
								    jsonData: Ext.encode(record.getData()),
								    success: function(response){
								        var text = response.responseText;
								        if (text==1) {
													Ext.MessageBoxUtil.msg('提示', '操作成功!');
										} else {
													Ext.MessageBoxUtil.msg('提示', '操作失败!');
										}
								    }
								});
					   		}
				       });
	}
});